require 'JournalXMLib'

class ElementQuery

  def queryDates(date)
    dateImages = []
    self.destinations.each do |destination|
      destination.photos.each do |photo|
        if date == photo.datetaken.datetakenElement[0].to_s
          dateImages.push(photo)
      end
    end
    return dateImages
  end
      
  def queryCities(city)
    cityImages = []
    self.destinations.each do |destination|
      destination.photos.each do |photo|
        if city == photo.city.cityElement[0]
          cityImages.push(photo)
        end
      end
      return cityImages
    end
  
  def queryCountry(country)
    countryImages = []
    self.destination.each do |destination|
      destination.photos.each do |photo|
        if country == photo.country.countryElement[0]
          countryImages.push(photo)
        end
      end
      return countryImages
    end
    
  def queryTrip(trip)
    tripImages = []
    self.trips.each do |trip|
      if trip == trip.tripElement[0]
        tripImages.push(trip)
      end
    end
    return tripImages
  end
  
  monthmap = {"Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12 }
    
  def chronology    #finish this later!!!
    timeImages = []
    dates = []
    self.trips.each do |trip|
      trip.destinations.each do |destination|
        destination.photos.each do |photo|
          date = photo.datetaken.datetakenElement[0].to_s
          year = date[9..12]
          month= date[0..2]
          day= date[4..5]
          dates.push([year, month, day])
        end
      end
      return tripImages
    end
  end
  
